package com.techwells.applicationMarket.util.apk;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import net.dongliu.apk.parser.ApkFile;
import net.dongliu.apk.parser.bean.ApkMeta;

/**
 * 解析安装包的apk的基本信息
 * 	https://github.com/hsiafan/apk-parser
 * @author 爱撒谎的男孩
 */
public class AnalyseApkUtils {
	/**
	 * 获取apk的详细信息
	 * @param filePath 安装包的路径
	 * @throws IOException
	 */
	public static Map<String, Object> getApkInfo(String filePath) throws IOException {
		try (ApkFile apkFile = new ApkFile(new File(filePath))) {
			ApkMeta apkMeta = apkFile.getApkMeta();
			Map<String, Object> map=new HashMap<>();
			map.put("label", apkMeta.getLabel());
			//版本名称
			map.put("versionName", apkMeta.getVersionName());   
			//安装包名
			map.put("packageName", apkMeta.getPackageName());
			return map;
		}
	}
	
	public static void main(String[] args) throws IOException {
		getApkInfo("C:/images/火币Pro-3.5.2.apk");
	}
}
